package com.zdsoft.blp.zongbuju.shouye.linliquan.activity;

import android.content.Intent;
import android.text.Html;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.zdsoft.blp.R;
import com.zdsoft.blp.gongyong.API.API;
import com.zdsoft.blp.gongyong.fanhui.FanHuiView;
import com.zdsoft.blp.gongyong.imageFrame.IvFrameView;
import com.zdsoft.blp.gongyong.net.BaseActivity;
import com.zdsoft.blp.gongyong.net.Net;
import com.zdsoft.blp.gongyong.net.NetCallback;
import com.zdsoft.blp.zongbuju.shouye.linliquan.adapter.LLPingLunAdapter;
import com.zdsoft.blp.zongbuju.shouye.linliquan.entity.LinLi;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/9/1.
 */
public class XQLYActivity extends BaseActivity implements NetCallback{
    private ListView lv;
    private FanHuiView fh;
    private IvFrameView iv;
    private ImageView pinglun;
    private TextView tv_biaoti;
    private TextView tv_lianxiren;
    private TextView tv_phone;
    private TextView tv_content;
    private Intent intent;
    private  TextView ershou_pinglun;
    private List<LinLi>list;
   private LinLi linLi;
    private List<String>mlist;
    @Override
    protected void init() {
        setContentView(R.layout.linli_zizhuluyou_zizhuluyou);
        lv=find(R.id.ly_xlv);
        lv.setFocusable(false);//取消焦点
        fh=find(R.id.fh);
        pinglun=find(R.id.pinglun);
        iv=find(R.id.iv);
        tv_biaoti=find(R.id.tv_biaoti);
        tv_lianxiren=find(R.id.tv_lianxiren);
        tv_phone=find(R.id.tv_phone);
        tv_content=find(R.id.tv_content);
        ershou_pinglun=find(R.id.ershou_pinglun);

        fh.getTv_title().setText("自助旅游");
        intent=getIntent();
        final String id=intent.getStringExtra("id");

        Net net=new Net();
        net.url= API.LYINFO_URL;
        net.nameSpace=API.LYINFO_NAMESPACE;
        net.methodName=API.LYINFOCONTENT ;
        Map<String,Object> map=new HashMap<>();
        map.put("id",id);
        net.parms=map;
        getServer(net,this);
        //跳转评论界面
        pinglun.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent=new Intent(XQLYActivity.this,LLHFActivity.class);
                intent.putExtra("id","4");
                startActivity(intent);
            }
        });

//      设置listview不可滑动
        lv.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
    }
    @Override
    public void onResponse(boolean flag, int code, String res) {
        Log.e("res",res);
        list=new ArrayList<>();
        mlist=new ArrayList<>();
        String picture="";
        try {
            JSONObject object=new JSONObject(res);
            String content=object.getString("content");
            String title=object.getString("title");
            String contactPhone=object.getString("contactPhone");
            String contact=object.getString("contact");
            String replyNum=object.getString("replyNum");
            tv_biaoti.setText(title);
            tv_content.setText("描述: "+Html.fromHtml(content));
            tv_lianxiren.setText(contact);
            tv_phone.setText(contactPhone);
            ershou_pinglun.setText(replyNum);
            JSONArray array=object.getJSONArray("replySet");
            for(int i=0;i<array.length();i++){
                JSONObject object2=array.getJSONObject(i);
                String pcontent=object2.getString("content");
                String replyUserHeadimgurl=object2.getString("replyUserHeadimgurl");
                String replyTime=object2.getString("replyTime");
                String replyUserName=object2.getString("replyUserName");
                linLi=new LinLi(replyUserName,pcontent,replyUserHeadimgurl,replyTime);
                list.add(linLi);

            }
            LLPingLunAdapter adapter=new LLPingLunAdapter(list,this);
            lv.setAdapter(adapter);
            JSONArray array2=object.getJSONArray("picPathSet");

            for(int j=0;j<array2.length();j++){
                JSONObject object3=array2.getJSONObject(j);
                picture=object3.getString("picPath");
                mlist.add(picture);
            }
           if(!picture.equals("")){
               iv.show(mlist);
           }

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
